<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>   
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>  
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>  
<%@ taglib uri="http://shiro.apache.org/tags" prefix="shiro" %>   
<%@ taglib prefix="dict" uri="/WEB-INF/tld/dict.tld" %>  
<c:set var="ctx" value="${pageContext.request.contextPath}"/> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<jsp:include page="../include.jsp"/>
<script type="text/javascript">
	var dataGrid;
	var itemsObj;
	
	$(function() {
		 //初始化数组字典
		itemsObj = <dict:getDictItem dictCode="DICT_SEX"/>;
		
		dataGrid = $('#dg').datagrid({
			title:'系统参数配置',
			url:'${ctx}/sysConfig/getPageData.do',
			nowrap:true,
			striped:true,
			idField:'id',
			pagination:true,
			fit:true,
			fitColumns:true,
			frozenColumns:[[
				{field:'id',checkbox :true}
			]],
			sortName:'UPDATE_TIME',
			sortOrder:'desc',
			rownumbers: true, //是否加行号 
			columns:[[	   			
	    		 {field:'configName',title:'配置名称',width:50,align:'left'},
	    		 {field:'configCode',title:'配置编码',width:50,align:'left'},
	    		 {field:'configValue',title:'配置值',width:50,align:'right'},
	    		 {field:'configDescr',title:'配置描述',width:300,align:'center'},
	    		 {field:'action',title:'操作',width:100,formatter:formatterOpt} 
			]],
			toolbar : '#toolbar',
			onLoadSuccess: function(data){
				$("#dg").datagrid('tooltip',['cstr_name','cstr_adds','crpn_adds']);
			},
			onHeaderContextMenu: function(e, field){
                e.preventDefault();
                $(this).datagrid('columnMenu').menu('show', {
                    left:e.pageX,
                    top:e.pageY
                });
            },
		}).datagrid('columnMoving');
		
	});
	
	function formatterOpt(value, row, index){
		return $.formatString('<a href="javascript:void(0);" onclick="view(\'{0}\');">{1}</a>', row.dictId,'字典项目配置'); 
	}
	
	function formatterFlag(value, row, index){
		if(value=="0"){
			return "停用";
		}else if(value =="1"){
			return "启用";
		}else{
			return value;
		}
	}
	
	function formatterShortName(value, row, index){
		if(row.provinceCity){
			return row.provinceCity.shortName;
		}
		return value;
	}
	
	function view(lcns_code){
		parent.$.modalDialog({
			title:'客户信息',
			iconCls:'icon-page',
			href:'${ctx}/customer/toTMdmCstrView?lcnsCode='+lcns_code,
			width:'60%',
			height:'70%',
			resizable:true,
			collapsible:true,
			maximizable:true			
		});
	}
	
	function add() {
		parent.$.modalDialog({
			title:'添加系统配置',
			iconCls:'icon-save',
			href:'${ctx}/sysConfig/toSysConfigAdd.do',
			width:'60%',
			height:'90%',
			resizable:true,
			collapsible:true,
			maximizable:true,
			buttons:[{
				text:'提交',
				iconCls:'icon-ok',
				handler:function() {
					parent.$.modalDialog.openner_dataGrid = dataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
					var f = parent.$.modalDialog.handler.find('#form');
					f.submit();
				}
			},{
				text:'取消',
				iconCls:'icon-cancel',
				handler:function() {
					parent.$.messager.confirm('系统提示', '确定要关闭当前窗口?', function(r){
		                if (r){
		                	parent.$.modalDialog.handler.dialog('close');
		                }
		            });					
				}
			}]
		});
	}
	
	function doSearch(){
		var params=$('#queryForm').serializeObject();
		$('#dg').datagrid('load',params);  
	}
	
	function doClear(){
		$('#queryForm').form("clear");
	}
	
	function del(id){
		if (typeof(id) == 'undefined') {
			var rows = dataGrid.datagrid('getSelections');
			if(rows.length != 1){
				parent.$.messager.alert('系统提示', '请选择一条记录！', 'warning');
				return;
			}
			id = rows[0].id;
		} else {
			dataGrid.datagrid('unselectAll').datagrid('uncheckAll');
		}
		parent.$.messager.confirm('询问', '您是否要删除当前用户？', function(b){ if(b) {
				parent.$.messager.progress({
					title : '提示',
					text : '数据处理中，请稍后....'
				});
				$.ajax({
	   				type: "POST",
	   				url: '${ctx}/sysConfig/delList.do',
	   				dataType:"json",
	   				data:{
   						ids : id
   					},
	   				success: function(result){
	     				if(result.success == true) {
     						parent.$.messager.alert('系统提示', result.msg, 'info');	
							dataGrid.datagrid('reload');
	     				} else {
	     					parent.$.messager.alert('系统提示', result.msg, 'error');
	     				}    				
	   				}  				
				});
				parent.$.messager.progress('close');	
			} 
		});
	}
	
	
	function batchDel(){
		var rows = dataGrid.datagrid('getChecked');
		var ids = [];
		if (rows.length > 0) {
			parent.$.messager.confirm('确认', '您是否要删除当前选中的项目？', function(b){ if(b){										
					$.each(rows,function(n,row) {			           
			            ids.push(row.id);
			        });					
					$.ajax({
	   					type: "POST",
	   					url: '${ctx}/sysConfig/delList.do',
	   					dataType:"json",
	   					data:{
	   						ids : ids.join(',')
	   					},
	   					success: function(result) {	   						
	     					if(result.success == true) {	     						
								parent.$.messager.alert('提示', result.msg, 'info');								
								dataGrid.datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
								dataGrid.datagrid('reload');
	     					} else {
	     						parent.$.messager.alert('错误', result.msg, 'error');		     						
	     					}	     				
		   				}
					});
					parent.$.messager.progress('close');	
				}
			});
		} else {
			parent.$.messager.alert('系统提示','请选择至少一条记录!','warning');
		}
	}
	
	
	function udpate(id){
		if (typeof(id) == 'undefined') {
			var rows = dataGrid.datagrid('getSelections');				
			if(rows.length != 1){
				parent.$.messager.alert('系统提示', '请选择一条记录！', 'warning');
				return;
			}
			id = rows[0].tmId;	
		} else {
			dataGrid.datagrid('unselectAll').datagrid('uncheckAll');
		}
		parent.$.modalDialog({
			title:'编辑系统配置',
			iconCls:'icon-edit',
			width:'60%',
			height:'90%',
			resizable:true,
			collapsible:true,
			maximizable:true,
			href:'${ctx}/sysConfig/toView?id=' + id,
			buttons:[{
				text:'修改',
				iconCls:'icon-ok',
				handler : function() {
					parent.$.modalDialog.openner_dataGrid = dataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
					var f = parent.$.modalDialog.handler.find('#form');
					f.submit();
				}
			},{
				text:'取消',
				iconCls:'icon-cancel',
				handler:function(){
					parent.$.messager.confirm('系统提示', '确定要关闭当前窗口?', function(r){
		                if(r){
		                	parent.$.modalDialog.handler.dialog('close');
		                }
		            });					
				}
			}]
		});
	}
	
	function setHeight(){
		var c = $('#cc');
		var p = c.layout('panel','north');	// get the north panel
		var oldHeight = p.panel('panel').outerHeight();
		p.panel('resize', {height:'auto'});
		var newHeight = p.panel('panel').outerHeight();
		c.layout('resize',{
			height: (c.height() + newHeight - oldHeight)
		});
	}

</script>
</head>
<body>
	<div id="cc" class="easyui-layout" data-options="fit:true">
	    <div data-options="region:'north',border:false" style="height:50px;padding-top:10px;padding-left:5px">	        
	        <form id="queryForm" method="post">			
				<input class="easyui-textbox" name="userName" label="用户名:" labelPosition="left" data-options="" style="width:25%;height:22px;">
				<input class="easyui-textbox" name="realName" labelWidth="100px" label="名称:" labelPosition="left" data-options="" style="width:25%;height:22px;">
				<select class="easyui-combobox" name="gender" label="性别:" labelWidth="50px" labelPosition="left" editable="false" style="width:20%;height:24px;">
					<option value="">全部</option>							
					<c:forEach items="${dictItems}" var="item">
						<option value="${item.itemValue}" >${item.itemText}</option>
					</c:forEach>
				</select>
				<a onclick="doSearch();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-search'">查询</a>
				<a onclick="doClear();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-reload'">重置</a>				
			</form>
	    </div>
		<div data-options="region:'center',border:false">
		     <table id="dg"></table>
		 </div>
	</div>
	
	<div id="toolbar" style="display: none;">
		<a onclick="add();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'">添加</a>
		<a onclick="udpate();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-edit'">修改</a>
		<a onclick="batchDel();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-remove'">删除</a>
	</div>
</body>
</html>